import UIKit

class OpenSourceViewController: UIViewController {

  override func viewDidLoad() {
    super.viewDidLoad()
    title = "开源组件声明"
    view.backgroundColor = .systemBackground
    setupTextView()
  }

  private func setupTextView() {
    let textView = UITextView()
    textView.translatesAutoresizingMaskIntoConstraints = false
    textView.isEditable = false
    textView.isSelectable = true
    textView.font = UIFont.systemFont(ofSize: 16)
    textView.textColor = .label
    textView.backgroundColor = .clear
    textView.text = """
      本应用部分功能基于以下开源项目构建：

      项目名称：Hamster
      作者：imfuxiao
      项目地址：https://github.com/imfuxiao/Hamster
      开源协议：MIT License

      我们在遵守 MIT 协议的前提下，基于 Hamster 项目的部分代码进行了功能扩展与界面定制。本应用与原项目无商业关联，特此致谢原作者的贡献。

      以下为原项目的版权声明（节选）：

      Copyright (c) 2022 imfuxiao

      Permission is hereby granted, free of charge, to any person obtaining a copy
      of this software and associated documentation files...
      """

    view.addSubview(textView)
    NSLayoutConstraint.activate([
      textView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
      textView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 16),
      textView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -16),
      textView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
    ])
  }
}
